package org.example.env_boot.repository;

import org.example.env_boot.entity.AQI;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * AQI数据访问接口
 */
@Repository
public interface AQIRepository extends JpaRepository<AQI, Integer> {
    
    /**
     * 根据SO2、CO、PM2.5浓度值判断AQI级别
     */
    @Query("SELECT a FROM AQI a WHERE (:so2Value BETWEEN a.so2Min AND a.so2Max) " +
           "AND (:coValue BETWEEN a.coMin AND a.coMax) " +
           "AND (:spmValue BETWEEN a.spmMin AND a.spmMax)")
    Optional<AQI> findAQIByValues(@Param("so2Value") Integer so2Value,
                                  @Param("coValue") Integer coValue,
                                  @Param("spmValue") Integer spmValue);
    
    /**
     * 获取所有AQI级别信息，按级别排序
     */
    List<AQI> findAllByOrderByAqiIdAsc();
} 